﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace BO
{
    partial class SysRole
    {
        protected override void UpdateChildren(List<DbCommand> cmdList)
        {
            if (IsDeleted)
            {
                ISysUserRoleList.Clear();
                IRoleAccessList.Clear();
            }
            if(_ISysUserRoleList!=null)
                _ISysUserRoleList.Update(cmdList);
            if(_IRoleAccessList!=null)
                _IRoleAccessList.Update(cmdList);
        }
        public override bool IsDirty
        {
            get
            {
                return base.IsDirty || IsChildDirty(_ISysUserRoleList,_IRoleAccessList);
            }
        }
     
        private SysUserRoleList _ISysUserRoleList = null;
        public SysUserRoleList ISysUserRoleList
        {
            get
            {
                if (_ISysUserRoleList == null)
                {
                    _ISysUserRoleList = ListFactory<SysUserRoleList>.GetList(string.Format("RoleName='{0}'", this.RoleName));
                }
                return _ISysUserRoleList;
            }
        }

        private RoleAccessList _IRoleAccessList;
        /// <summary>
        /// 只用于获取当前用户的操作权限,不能添加和修改该集合.
        /// </summary>
        public RoleAccessList IRoleAccessList
        {
            get
            {
                if (_IRoleAccessList == null)
                {
                        _IRoleAccessList = ListFactory<RoleAccessList>.GetList(string.Format("RoleName ='{0}'", RoleName));
                        _IRoleAccessList.AllowEdit = false;
                  
                    _IRoleAccessList.SetHeader(this);
                }
                return _IRoleAccessList;
            }
        }
        
    }
}
